package com.cos.sm.services.impl;

import com.cos.sm.dao.EmpMapper;
import com.cos.sm.entity.Emp;
import com.cos.sm.services.EmpServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.FileNotFoundException;
import java.util.List;

/**
 * @author: COS
 * @time: 2022/9/27 14:42
 * @description:
 * @Transactional 写在类上代表,这个类下所有方法都应用他的事务规则
 */
@Service
//@Component
@Transactional(isolation = Isolation.DEFAULT,timeout = 200,propagation = Propagation.REQUIRED)
public class EmpServicesImpl implements EmpServices {
    /**
     * @author: COS
     * @return:
     * @time: 2022/9/27 17:24
     * @description: 自动注入(自动装配) byType
     * 在@AutoWired 基础上加上 @Qualifier("empMapper") 转为byName来自动注入
     *
     *
     * @Resource 使用java反射完成的自动注入
     * 1. 他会先使用BeanName来进行注入,如果找不到,就会自动转为ByType来注入
     */
    @Autowired
    // @Qualifier("empMapper")
//    @Resource *
    private EmpMapper mm;
//    @Value("${haha}")
//    private String a ;
    @Override
    public int addEmp(Emp emp) throws FileNotFoundException {
        int i = mm.addEmp(emp);
//        System.out.println(10/0);
//        new FileInputStream("");
        return i;
    }
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    @Override
    public List<Emp> getAll() {
        return mm.getAll();
    }


}
